package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "分类品牌管理")
@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    /**
     * 查询指定分类下包含品牌列表
     * @param category3Id
     * @return
     */
    @GetMapping("/findTrademarkList/{category3Id}")
    public Result getTrademarkList(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.getTrademarkList(category3Id);
        return Result.ok(list);
    }

    /**
     * 查询指定分类下未关联品牌列表(可选品牌列表)
     * @param category3Id
     * @return
     */
    @GetMapping("/findCurrentTrademarkList/{category3Id}")
    public Result getCurrentTrademarkList(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.getCurrentTrademarkList(category3Id);
        return Result.ok(list);
    }


    /**
     * 将选中品牌关联到指定分类
     * @param vo
     * @return
     */
    @PostMapping("/save")
    public Result saveBaseCategoryTrademark(@RequestBody CategoryTrademarkVo vo){
        baseCategoryTrademarkService.saveBaseCategoryTrademark(vo);
        return Result.ok();
    }


    /**
     * 删除指定分类下品牌
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public Result removeCategoryTrademark(@PathVariable("category3Id") Long category3Id, @PathVariable("trademarkId") Long trademarkId){
        baseCategoryTrademarkService.removeCategoryTrademark(category3Id, trademarkId);
        return Result.ok();
    }
}
